home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7321 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  79 lines

  1. Path: news.dseg.ti.com!news    
  2. From: grubin@ti.com (Geoffrey Rubin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [HLP] Easy Problem w/ Classes!
  5. Date: 22 Feb 1996 18:46:14 GMT
  6. Organization: AWP
  7. Message-ID: <4gidlm$fat@mksrv1.dseg.ti.com>
  8. References: <4gfn3v$jp@news.umbc.edu>
  9. NNTP-Posting-Host: cna0185662.dseg.ti.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4gfn3v$jp@news.umbc.edu>, ssopre1@umbc.edu says...
  15. >
  16. >Hello all
  17. >  Heres a little problem that I need help with. 
  18. >
  19. >// Point.h contains
  20. >Class Point {
  21. >private: int x;
  22. >         int y;
  23. >
  24. >public: Point();
  25. >}
  26. >
  27. >// LineSeg.h contains 
  28. >class LineSeg{
  29. >private:
  30. >        Point end;
  31. >        Point start;
  32. >public:         
  33. >        LineSeg();
  34. >}
  35. >
  36. >// LineSeg.C contains
  37. >LineSeg::LineSeg()
  38. >{
  39. > Point.end.x=0;  // Are these valid? 
  40. > Point.end.y=0;  // What do I need to add/del here? 
  41. > Point.start.x=0;
  42. > Point.start.y=0;
  43. >}
  44. >
  45. >Basically, LineSeg() is supposed to set starting and ending
  46. >points to zero. Compiler goes berserkoid .. . 
  47. Since x and y are private members of Point, you can not access them
  48. in LineSeg. You can add other versions of your constructor to initialize
  49. x and y such as:
  50.   Point(int TheX ...)
  51. and initialize them like:
  52.   Point end(0,0) ; ...
  53.  
  54. Or you can add other methods to Point to set x and y values 
  55. such as:
  56. class Point 
  57. {
  58.   ...
  59.   public:
  60.     void SetX(int TheX) ;
  61. }
  62.  
  63. and then use them:
  64.  
  65.   end.SetX(0) ;
  66.  
  67. Or you can make x and y public members (not recommended)
  68. and do the following in LineSeg:
  69.  
  70.    end.x = 0 ;
  71.    start.y = 0 ;
  72.  
  73. But you can never do the following!!!:
  74.   Point.end.x=0; 
  75.  
  76. Geoffrey
  77.  
  78.  
  79.